//
//  BuyCell.m
//  随便点
//
//  Created by ZC on 15/3/19.
//  Copyright (c) 2015年 qfsoft. All rights reserved.
//

#import "BuyCell.h"
#import "AppDelegate.h"
#import "ShopDetailViewController.h"
#import "picbig.h"
@implementation BuyCell{
    int i ;
    AppDelegate *delegate;
    
}

- (void)awakeFromNib {
    delegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    i = 0;
    self.BuyImage.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"moren.jpg"]];
    self.BuyImage.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoTapped)];
    [self.BuyImage addGestureRecognizer:singleTap];//点击图片事件
    
}
-(void)photoTapped{
    [picbig showImage:self.BuyImage];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (IBAction)AddbuttonClick:(id)sender {
    
    //“减号”按钮隐藏
    self.reduceButton.hidden=NO;
    
    ShopDetailViewController *detaiVC = delegate.detailsVC;
    
    //当前某行菜品点击数量
    int number = [detaiVC.BigArray[detaiVC.index][_indexpath][@"数量"] intValue];
    detaiVC.BigArray[detaiVC.index][_indexpath][@"数量"] = [NSString stringWithFormat:@"%d",++number];
    detaiVC.BigArray[detaiVC.index][_indexpath][@"商品id"] = self.caipingid;
    
    //总价格等于 上次总价格 ＋ 菜品单价
    detaiVC.AllPrice += [self.BuyPrice.text floatValue];

    //每点击一次“加号”总数量 ＋1
    detaiVC.total += 1;
    
    [detaiVC.tableViewRight reloadData];

}

- (IBAction)ReduceButtonClick:(id)sender {
    
        AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication]delegate];
        
        ShopDetailViewController *detaiVC = delegate.detailsVC;
        //当前某行菜品点击数量
        int number = [detaiVC.BigArray[detaiVC.index][_indexpath][@"数量"] intValue];
        detaiVC.BigArray[detaiVC.index][_indexpath][@"数量"] = [NSString stringWithFormat:@"%d",--number];
        

        //总价格等于 上次总价格 － 菜品单价
        detaiVC.AllPrice -= [self.BuyPrice.text floatValue];
    
        //每点击一次“减号”总数量 －1
        detaiVC.total -= 1;
        
        [detaiVC.tableViewRight reloadData];
}

@end
